from django.db import models
from vistor.models import *


# Create your models here.


class School(models.Model):
    uname = models.CharField(max_length=30, verbose_name='园所名称')
    shortname = models.CharField(max_length=30, verbose_name='园所简称')
    logo = models.ImageField(upload_to='static/images', verbose_name='园所logo')
    introduce = models.TextField(verbose_name='简介')
    address = models.CharField(max_length=30, null=False, verbose_name='地址')
    copyrightmessage = models.CharField(max_length=100, null=False, verbose_name='版权信息')
    version = models.CharField(max_length=100, verbose_name='版本信息')
    starttime = models.DateField(verbose_name='开始时间')
    endtime = models.DateField( verbose_name='到期时间')
    headmastername = models.CharField(max_length=10, null=False, verbose_name='园长姓名')
    headmasterphone = models.CharField(max_length=11, null=False, verbose_name='园长电话')
    headmasterphoto = models.ImageField(upload_to='static/photo', verbose_name='园长头像')
    latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, verbose_name='纬度')
    longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, verbose_name='经度')
    isDlete = models.BooleanField(default=False, verbose_name='删除')

    # 与用户表1:1
    role = models.ForeignKey(Role, verbose_name='身份')

    def __str__(self):
        return self.uname

    class Meta:
        db_table = 'school'
        verbose_name = '园所表'
        verbose_name_plural = verbose_name


class Video(models.Model):
    title = models.CharField(max_length=60, null=False, verbose_name='视频标题')
    site = models.URLField(verbose_name='视频ID')
    isDelete = models.BooleanField(default=False, verbose_name='删除')

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'video'
        verbose_name = '视频表'
        verbose_name_plural = verbose_name


class Ability(models.Model):
    powerTitle = models.CharField(max_length=50, null=False, verbose_name='能力线名称')
    # questionAmount = models.IntegerField(null=True, verbose_name='月龄总数')
    isDelete = models.BooleanField(default=False, verbose_name='删除',)
    # 与School表(M:1)
    school = models.ForeignKey(School, related_name='school_powers', on_delete=models.CASCADE, verbose_name='园所')
    # 与Video表（m:m）
    videos = models.ManyToManyField(Video, related_name='abilities', verbose_name='视频', null=True)

    def __str__(self):
        return self.powerTitle

    class Meta:
        db_table = 'ability'
        verbose_name = '能力线表'
        verbose_name_plural = verbose_name


class Moonage(models.Model):
    age = models.IntegerField(null=False, verbose_name='月龄')
    # amount = models.IntegerField(null=True, verbose_name='题目数量')
    isDelete = models.BooleanField(default=False, verbose_name='删除')
    # 与Video表（m:1）
    shipin = models.ForeignKey(Video, verbose_name='视频')
    # 与Ability表（M:1)
    abilities = models.ForeignKey(Ability, null=True, on_delete=models.CASCADE, verbose_name='能力线')

    def __str__(self):
        return str(self.age)

    class Meta:
        db_table = 'moonage'
        verbose_name = '月龄表'
        verbose_name_plural = verbose_name


class Test(models.Model):
    biaoti = models.CharField(max_length=100, null=False, verbose_name='标题')
    value = models.IntegerField(null=False, verbose_name='分值')
    isDelete = models.BooleanField(default=False, verbose_name='删除')

    # 与Ability表（m:1)
    # powers = models.ForeignKey(Ability, related_name='tests', verbose_name='能力线')
    # 与月龄表(m:1)
    yueling = models.ForeignKey(Moonage, related_name='tests', on_delete=models.CASCADE, verbose_name='月龄', null=True)

    def __str__(self):
        return self.biaoti

    class Meta:
        db_table = 'test'
        verbose_name = '测评题表'
        verbose_name_plural = verbose_name


class Student(models.Model):
    uname = models.CharField(max_length=10, null=False, verbose_name='姓名')
    birth = models.DateField(verbose_name='出生日期')
    gender = models.CharField(max_length=1, null=False, verbose_name='性别')
    photo = models.ImageField(upload_to='static/photo', default='static/photo/3.jpg', verbose_name='头像')
    openschool = models.DateField(null=True, verbose_name='开学时间')
    endschool = models.DateField(null=True, verbose_name='结束时间')

    # 与园所(m:1)
    school = models.ForeignKey(School, verbose_name='园所')

    def __str__(self):
        return self.uname

    class Meta:
        db_table = 'student'
        verbose_name = '学生表'
        verbose_name_plural = verbose_name


class Testresutl(models.Model):
    yueling = models.CharField(max_length=2, null=False, verbose_name='月龄')
    score = models.IntegerField(null=True, verbose_name='成绩')

    # 与Student表（m:1）
    xuesheng = models.ForeignKey(Student, null=True, related_name='test_results', verbose_name='学生')

    def __str__(self):
        return self.xuesheng.uname

    class Meta:
        db_table = 'testresult'
        verbose_name = '测评结果表'
        verbose_name_plural = verbose_name


class Testdetail(models.Model):
    powername = models.CharField(max_length=50, verbose_name='能力线')
    result = models.CharField(max_length=1, null=True, verbose_name='结果')

    # 与Testresult表（m:1）
    testresult = models.ForeignKey(Testresutl, verbose_name='测评结果')

    def __str__(self):
        return self.powername

    class Meta:
        db_table = 'testdetail'
        verbose_name = '测评详情表'
        verbose_name_plural = verbose_name


class Questionresult(models.Model):
    questionName = models.CharField(max_length=100, null=False, verbose_name='测评题')
    getscore = models.IntegerField(null=False, verbose_name='得分')

    # 与Testdetail表（m:1）
    testdetail = models.ForeignKey(Testdetail, verbose_name='测评详情')

    def __str__(self):
        return self.questionName

    class Meta:
        db_table = 'questionresult'
        verbose_name = '测评题结果表'
        verbose_name_plural = verbose_name


class Choicequestions(models.Model):
    choiceName = models.CharField(max_length=100, null=False, verbose_name='测评题选项')
    grade = models.IntegerField(null=False, verbose_name='选项分值')

    # 与Test表（m:1）
    test = models.ForeignKey(Test, related_name='question_choices', on_delete=models.CASCADE, verbose_name='测评题')

    def __str__(self):
        return self.choiceName

    class Meta:
        db_table = 'choicequestions'
        verbose_name = '测评题选项表'
        verbose_name_plural = verbose_name


class Recordresult(models.Model):
    title = models.CharField(max_length=100, null=False, verbose_name='测评题选项')
    score = models.IntegerField(verbose_name='选项分值')

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'recordresult'
        verbose_name = '测评题记录结果表'
        verbose_name_plural = verbose_name











